package com.xiaobao.coalproperty.other.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.xiaobao.coalproperty.R;
import com.xiaobao.coalproperty.module.user.model.entity.UserDealEntity;

import java.util.ArrayList;
import java.util.List;

public class UserDealAdapter extends RecyclerView.Adapter<UserDealAdapter.ViewHolder> {


    private Context mContext;

    private List<UserDealEntity.DataBean.ListBean> mAdapterData;

    public UserDealAdapter(Context mContext) {
        this.mContext = mContext;
    }

    public List<UserDealEntity.DataBean.ListBean> getAdapterData() {
        return mAdapterData;
    }

    public void setAdapterData(List<UserDealEntity.DataBean.ListBean> mAdapterData) {
        this.mAdapterData = mAdapterData;
        this.notifyDataSetChanged();
    }

    public void addAdapterData(List<UserDealEntity.DataBean.ListBean> mAdapterData) {
        if (this.mAdapterData == null) {
            this.mAdapterData = new ArrayList<>();
        }
        this.mAdapterData.addAll(mAdapterData);
        this.notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_adapter_user_deal, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.tvTime.setText(mAdapterData.get(position).getCreate_time());
        if (mAdapterData.get(position).getType().equals("1")) {
            holder.tvType.setText("买入");
        }
        if (mAdapterData.get(position).getType().equals("2")) {
            holder.tvType.setText("卖出");
        }
        if (mAdapterData.get(position).getType().equals("3")) {
            holder.tvType.setText("提现");
        }
        holder.tvMoney.setText(mAdapterData.get(position).getMoney());
    }

    @Override
    public int getItemCount() {
        if (mAdapterData == null) {
            return 0;
        }
        return mAdapterData.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvTime, tvType, tvMoney;

        public ViewHolder(View itemView) {
            super(itemView);
            tvTime = itemView.findViewById(R.id.user_deal_time);
            tvType = itemView.findViewById(R.id.user_deal_type);
            tvMoney = itemView.findViewById(R.id.user_deal_money);
        }
    }
}
